<template>
  <div class="login-page">
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>登录</span>
        </div>
      </template>
      <el-form :model="form" label-width="100px" @submit.prevent="handleLogin">
        <el-form-item label="用户名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" native-type="submit">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>

  </div>
</template>

<style scoped>
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height:33vh;
  background: #254;
}
.box-card {
  width: 480%;
  padding: 20px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.card-header {
  text-align: center;
}
</style>
<script>
import {ref}from "vue";
import {ElNotification} from "element-plus";
import router from "../router/index.js";
export default {
  setup() {
    const form = ref({username: "", password: ""});
    const handleLogin =() => {
      if (form.value.username === "admin" && form.value.password === "admin") {
        localStorage.setItem('isAuthenticated', 'true');
        ElNotification({
          title:'成功',
          message:'登陆成功',
          type:"success"
        })
        router.push('/page2')
      }else{
        ElNotification({
          title:'失败',
          message:'用户名或密码错误，请重试',
          type:"error"
        })
      }
    }
    return {form, handleLogin};
  }
}
</script>